package com.winona.ui;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.widget.TextView;

import com.taplinker.client.R;
import com.winona.Base1Activity;

public class VersionAcitivty extends Base1Activity {
	private ImageButton back;
	private TextView title, tv_version;
	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.version);
		findView();
		Animation animRef = AnimationUtils.loadAnimation(this, R.anim.anim1);
		title.setText("版本号");
		setLinstener();
	}

	private void setLinstener() {
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				intent = new Intent(VersionAcitivty.this, AboutActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.input, R.anim.out);
			}
		});

	}

	private void findView() {
		back = (ImageButton) findViewById(R.id.version_back);
		title = (TextView) findViewById(R.id.version_title);
		tv_version = (TextView) findViewById(R.id.tv_version);
		tv_version.setText(getVersion());
	}

	/**
	 * 获取应用程序的版本号
	 * 
	 * @return
	 */
	private String getVersion() {
		// 得到包管理器
		PackageManager pm = getPackageManager();
		try {
			PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
			return packageInfo.versionName;
		} catch (Exception e) {
			// can't reach
			e.printStackTrace();
			return "";
		}
	}
}
